import emitter from "./emitter";

const { ccclass, property } = cc._decorator;

@ccclass
export default class planeCollider extends cc.Component {
    isCollider = false;
    setPlaneHarm;
    onCollisionEnter(other, self) {
        if (this.isCollider) return
        this.isCollider = true;
        if (other.node.group == "enemyPlane" || other.node.group == "enemy_bullet" || other.node.group == "duYun" || other.node.group == "eggs") {
            if (this.setPlaneHarm) this.setPlaneHarm(1);
            if (other.node.group == "enemy_bullet") {
                if (other.node.parent.name.indexOf("pf") != -1) {
                    //回收子弹
                    emitter.emit("putEnemyBullet", other.node.parent);
                }
                else {
                    //回收子弹
                    emitter.emit("putEnemyBullet", other.node);
                }
            }
        }
        else if (other.node.group == "zhuWang") {
            if (this.setPlaneHarm) this.setPlaneHarm(other.node.group);
            emitter.emit("putEnemyBullet", other.node);
        }
        else if (other.node.group == "goods") {
            emitter.emit("setBulletType", other.node);
            other.node.removeFromParent();
            other.node.destroy();
        }
    }

    onCollisionExit() {
        this.isCollider = false;
    }
}
